package com.jckl.foodathon.widget;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jckl.foodathon.R;
import com.jckl.foodathon.model.StoresListWidget;

public class StoresListAdapter extends BaseAdapter{

	Context context;
	List<StoresListWidget> storesListWidget;

	public StoresListAdapter(Context context, List<StoresListWidget> storeList) {
		this.context = context;
		this.storesListWidget = storeList;
	}

	@Override
	public int getCount() {
		return storesListWidget.size();
	}

	@Override
	public Object getItem(int arg0) {
		return storesListWidget.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return storesListWidget.indexOf(getItem(arg0));
	}

	private class StoreListHolder {
		ImageView storeImage;
		TextView storeName;
		TextView storeArea;
		TextView storeDistance;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		StoreListHolder holder = null;

		LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.widget_storelist, null);
			holder = new StoreListHolder();

			holder.storeImage = (ImageView) convertView.findViewById(R.id.storelist_image);
			holder.storeName = (TextView) convertView.findViewById(R.id.storelist_name);
			holder.storeArea = (TextView) convertView.findViewById(R.id.storelist_area);
			
			StoresListWidget row_pos = storesListWidget.get(position);
			
	//		holder.storeImage.setImageResource(row_pos.get);
			holder.storeName.setText(row_pos.getStoreName());
			holder.storeArea.setText(row_pos.getStoreArea());
		
			convertView.setTag(holder);
		} else {
			holder = (StoreListHolder) convertView.getTag();
		}
		
		return convertView;
	}

}
